package leetcode.editor.cn;

/**
题目名字---:合并两个有序数组
题目编号---:88	
解题时间---:2021-10-17 10:37:14
*/

public class MergeSortedArray{
    public static void main(String[] args) {
        Solution solution = new MergeSortedArray().new Solution();
        //nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
        int [] nums1 = {1,2,3,0,0,0};
        int [] nums2 = {2,5,6};
        solution.merge(nums1,3,nums2,3);
    }
    
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int j =0;
        for (int i = m; i < m+n; i++) {
            nums1[i] = nums2[j++];
        }
        for (int i = 1; i < nums1.length; i++) {
            //想插入排序的一位
            int temp = nums1[i];
            //排好序的最后一位
            int k = i-1;
            for (; k >=0&&nums1[k]>temp; k--) {
                    nums1[k+1] = nums1[k];
            }
            nums1[k+1] = temp;
        }
    }
}
//leetcode submit region end(Prohibit modification and deletion)


}